package io.fredia.common.utils;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;

import java.util.*;

/**
 * 获取资源文件
 * 
 * @author : fredia
 * @since : 2017年10月13日
 * @version : v0.0.1
 */
public class GlobalConstant extends PropertyPlaceholderConfigurer {
	private static Map<String, String> properties = new HashMap<String, String>();

	@Override
	protected void processProperties(ConfigurableListableBeanFactory beanFactoryToProcess, Properties props)
			throws BeansException {
		super.processProperties(beanFactoryToProcess, props);
		for (String key : props.stringPropertyNames()) {
			properties.put(key, props.getProperty(key));
		}

	}

	public static String getString(String key) {
		try {
			return properties.get(key);
		} catch (Exception e) {
			return key;
		}

	}
}
